<style>
  .hot:hover {
    text-decoration: underline;
  }

  .layui-this a {
    color: #3382ff !important;
  }
</style>

<div class="fly-panel fly-column" style="background: none; margin-top: 15px;box-shadow: none;">
  <div class="layui-container">
    <ul class="layui-clear" style="background: #fff;">
      <li class="layui-hide-xs {$cateid == 0 ? 'layui-this' : ''}"><a href="/">全部</a></li>
      {foreach $catelist as $cate}
      <li class="{$cateid == $cate['id'] ? 'layui-this' : ''}">
        <a href="{:url('home/index/index',['cateid' => $cate['id']])}">{$cate['name']}</a>
      </li>
      {/foreach}
      <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>

      <!-- 用户登入后显示 -->
      <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('home/user/post')}">我发表的贴</a>
      </li>
      <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('home/user/collect')}">我收藏的贴</a>
      </li>
    </ul>

    <div class="fly-column-right layui-hide-xs" style="margin-right: 10px;">
      <span class="fly-search"><i class="layui-icon"></i></span>
      <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a>
    </div>
    <div class="layui-hide-sm layui-show-xs-block" style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
      <a href="jie/add.html" class="layui-btn">发表新帖</a>
    </div>
  </div>
</div>

<div class="layui-container">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md4">
      <!-- 签到 -->
      <div class="fly-panel fly-signin">
        <div class="fly-panel-title">
          签到
        </div>
        <div class="fly-panel-main fly-signin-main">
          {if condition="$signFlag"}
          <button class="layui-btn layui-btn-danger" id="LAY_signin">今日签到</button>
          <span>可获得<cite>5</cite>积分</span>
          {else/}
          <button class="layui-btn layui-btn-disabled" disabled id="LAY_signin">今日已签到</button>
          <span>已获得<cite>5</cite>积分</span>
          {/if}
        </div>
      </div>

      <!-- 本周热议 -->
      <div class="fly-panel">
        <h3 class="fly-panel-title">本周热议</h3>
        <ul class="fly-panel-main fly-list-static">
          {foreach $hotPost as $item}
          <li>
            <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $cateid])}" class="hot" target="_blank"
              style="color: #333;">{$item['title']}</a>
          </li>
          {/foreach}
        </ul>
      </div>

      <!-- 回贴周榜 -->
      <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
        <h3 class="fly-panel-title">回贴周榜</h3>
        <dl>
          <!--<i class="layui-icon fly-loading">&#xe63d;</i>-->
          {foreach $postReplys as $item}
          <dd>
            <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $cateid])}">
              <img src="/{$item['userinfo']['avatar']}"><cite>{$item.title}</cite><i>{$reply[$item['id']]}次回答</i>
            </a>
          </dd>
          {/foreach}
        </dl>
      </div>

      <!-- 二维码 -->
      <div class="fly-panel" style="padding: 20px 0; text-align: center;">
        <img src="/assets/home/images/weixin.jpg" style="max-width: 70%;" alt="layui">
        <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
      </div>
    </div>

    <div class="layui-col-md8">

      <!-- 顶置 -->
      <div class="fly-panel">
        <div class="fly-panel-title fly-filter">
          <a>置顶</a>
          <a href="#signin" class="layui-hide-sm layui-show-xs-block fly-right" id="LAY_goSignin"
            style="color: #FF5722;">去签到</a>
        </div>
        <ul class="fly-list">
          {foreach $postAll as $item}
          <li>
            <a href="{:url('home/user/index',['userid' => $item.user.id])}" class="fly-avatar">
              {if condition="is_file($item['user']['avatar'])" }
              <img src="/{$item['user']['avatar']}">
              {else /}
              <img src="/assets/home/images/default.jpeg" alt="">
              {/if}
            </a>
            <h2>
              <a class="layui-badge">{$item['cate']['name']}</a>
              <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $cateid])}">{$item['title']}</a>
            </h2>
            <div class="fly-list-info">
              <a href="user/home.html" link>
                <cite>{$item['user']['nickname']}</cite>
                <!--
                  <i class="iconfont icon-renzheng" title="认证信息：XXX"></i>
                  <i class="layui-badge fly-badge-vip">VIP3</i>
                  -->
              </a>
              <span>{$item['createtime']}</span>

              <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻"><i class="iconfont icon-kiss"></i>
                {$item['visit_text']}</span>
              {if condition="$item['accept']"}
              <span class="layui-badge fly-badge-accept layui-hide-xs">已结</span>
              {/if}
              <span class="fly-list-nums">
                <i class="iconfont icon-pinglun1" title="回答"></i> {$item['comment']}
              </span>
            </div>
            <div class="fly-list-badge">
              {if condition="$item['state'] != '0'"}
              <span class="layui-badge layui-bg-red">{$item.state_text}</span>
              {/if}
            </div>
          </li>
          {/foreach}
        </ul>
      </div>

      <div class="fly-panel" style="margin-bottom: 0;padding-bottom:2em;">

        <!-- 分类 -->
        <div class="fly-panel-title fly-filter">
          <a href="{:url('home/index/index',['cateid' => $cateid])}" class="{$accept == 2 ? 'layui-this' : ''}">全部</a>
          <span class="fly-mid"></span>
          <a href="{:url('home/index/index',['accept' => 0,'cateid' => $cateid])}"
            class="{$accept == 0 ? 'layui-this' : ''}">未结</a>
          <span class="fly-mid"></span>
          <a href="{:url('home/index/index',['accept' => 1,'cateid' => $cateid])}"
            class="{$accept == 1 ? 'layui-this' : ''}">已结</a>
          <span class="fly-mid"></span>
        </div>

        <!--  全部帖子 -->
        <ul class="fly-list">
          {foreach $postlist as $item}
          <li>
            <a href="{:url('home/user/index',['userid' => $item.user.id])}" class="fly-avatar">
              {if condition="is_file($item['user']['avatar'])" }
              <img src="/{$item['user']['avatar']}">
              {else /}
              <img src="/assets/home/images/default.jpeg" alt="">
              {/if}
            </a>
            <h2>
              <a class="layui-badge">{$item['cate']['name']}</a>
              <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $cateid])}">{$item['title']}</a>
            </h2>
            <div class="fly-list-info">
              <a href="user/home.html" link>
                <cite>{$item['user']['nickname']}</cite>
                <!--
                  <i class="iconfont icon-renzheng" title="认证信息：XXX"></i>
                  <i class="layui-badge fly-badge-vip">VIP3</i>
                  -->
              </a>
              <span>{$item['createtime']}</span>

              <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻"><i class="iconfont icon-kiss"></i>
                {$item['visit_text']}</span>
              {if condition="$item['accept']"}
              <span class="layui-badge fly-badge-accept layui-hide-xs">已结</span>
              {/if}
              <span class="fly-list-nums">
                <i class="iconfont icon-pinglun1" title="回答"></i> {$item['comment']}
              </span>
            </div>
            <div class="fly-list-badge">
              {if condition="$item['state'] != '0'"}
              <span class="layui-badge layui-bg-red">{$item.state_text}</span>
              {/if}
            </div>
          </li>
          {/foreach}
        </ul>

        <!-- 分页 -->
        <div>
          <div>
            {$pagestr}
          </div>
        </div>

      </div>
    </div>


  </div>
</div>

<script>
  layui.use('layer', function () {
    var layer = layui.layer
    var $ = layui.jquery;

    $("#LAY_signin").on("click", function () {
      $.ajax({
        type: "POST",
        url: `{:url('home/index/sign')}`,
        success: function (data) {
          console.log(data);
          if (data.result) {
            // 成功
            layer.msg(data.msg, {
              icon: 1,
              time: 2000,
            }, function () {
              // 收藏成功刷新界面
              location.reload();
            })
          } else {
            // 失败
            layer.msg(data.msg);
          }
        }
      })
    })
  })
</script>